﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ISS.IR.RRNMS.Library.DataAccess;

namespace ISS.IR.RRNMS.Library.BusinessLogic
{
    public class IR_User
    {
        public Guid UserId { get; set; }
        public string Username { get; set; }
        public string Password { get; set; }
        public string FullName { get; set; }

        public string Telephone { get; set; }
        public string Mobile { get; set; }
        public string Email { get; set; }

        public Item Manager { get; set; }
        public Item DefaultRole { get; set; }

        public UserPermissions Permissions { get; set; }

        public static Guid Login(string Username, string Password)
        {
            try
            {
                return DataAccess.Main.Login(Username, Password);
            }
            catch (Exception exc)
            { }

            return Guid.Empty;
        }

        public static UserPermissions SelectUserPermissions(Guid UserId)
        {
            return Main.SelectUserPermissions(UserId);
        }

        public static List<Item> SelectAllUsers()
        {
            try
            {
                return DataAccess.Main.SelectAllUsers();
            }
            catch (Exception exc)
            {

            }
            return new List<Item>();
        }

        public static List<Item> SelectAllUserRoles()
        {
            return DataAccess.Main.SelectAllUserRoles();
        }

        public IR_User()
        { }

        public IR_User(Guid UserId)
        {
            IR_User user = DataAccess.Main.SelectOneUser(UserId);

            this.UserId = user.UserId;
            this.FullName = user.FullName;
            this.Username = user.Username;
            this.Password = user.Password;
            this.Telephone = user.Telephone;
            this.Mobile = user.Mobile;
            this.Email = user.Email;
            this.DefaultRole = user.DefaultRole;
            this.Manager = user.Manager;
            this.Permissions = user.Permissions;
        }

        public void Save()
        {
            Main.SaveUser(this);
        }

        public void Delete()
        {
            Main.DeleteUser(this.UserId);
        }
    }

    public struct UserPermissions
    {
        public bool HasAccountPerm;
        public bool HasCalendarPerm;
        public bool HasSearchPerm;
        public bool IsAdmin;
    }
}
